import { defineStore } from 'pinia';

export const mainStore = defineStore({
  id: 'main',
  state: () => ({
    menuOpen: false,
    language: 'ch',
  }),
  // getters: {
  //   doubleCount: (state) => state.counter * 2
  // },
  actions: {
    changeMenuStatus(val?: boolean) {
      document.documentElement.scrollTop = 0;
      this.menuOpen = val ?? !this.menuOpen;
      if (this.menuOpen) {
        document.body.classList.add('body_menu_open');
      } else {
        document.body.classList.remove('body_menu_open');
      }
    },
    changeLanguage(val: string) {
      if (this.language === val) {
        return;
      }
      this.language = val;
      this.menuOpen = false;

      setTimeout(() => {
        window.location.reload();
      }, 500);
    },
  },
});
